/**
 * 商品列表
 * Name = ShopLayer
 * DateTime = Tue Jan 18 2022 12:59:35 GMT+0800 (中国标准时间)
 * Author = Created by zhj9922
 * FileBasename = ShopLayer.ts
 * gitee： https://gitee.com/coyeking
 */
 
import { _decorator, Component, Node,Layout,Prefab,instantiate } from 'cc';
const { ccclass, property } = _decorator;
import { UiBase } from '../../uiBase';
import { audioManager } from '../../../framework/audioManager';
import { uiManager } from '../../../framework/uiManager';
import { httpApi } from '../../../api/httpApi';
import { notifyEvent } from '../../../framework/notifyEvent';
import { constant } from '../../../define/constant';
 
@ccclass('ShopLayer')
export class ShopLayer extends UiBase {
    @property({
        type: Node,
        displayName:'容器',
    })
    public ui_content: Node = null;
    
    @property(Prefab)
    public ui_CommodityItem: Prefab = null;
	
    public result_data = new Array();
    private paytype: string = 'wxpay';//支付方式

	
    onEnable () {
        super.onEnable();

        notifyEvent.on(constant.NOTIFY_EVENT.notify_shopindex,this.onshop,this);

        uiManager.showWaiting(true);
        this.getGoodList();
    };
    
    onDestroy () {
        notifyEvent.off(constant.NOTIFY_EVENT.notify_shopindex,this.onshop,this);
    };

    onshop(index){
        console.log('商品id==>',index);


        uiManager.showToast('后台未开启该平台支付');
    }
    initUI(){
        let _this = this;
        for (let index = 0; index < _this.result_data.length; index++) {
            const element = _this.result_data[index];
            
            let tipPrefab:Node = instantiate(_this.ui_CommodityItem);
            let tipScript = tipPrefab.getComponent('CommodityItem');
            //@ts-ignore
            tipScript.init(element);
            _this.ui_content.addChild(tipPrefab);
            
        }
    }
	
    /**
     * 按钮点击事件
     * @param event 
     * @param customEventData 
     */
	private onClick (event: Event, customEventData: string) {
        audioManager.instance.playSound();
        if (customEventData == 'close'){
            return this.closeAction();
        }
        this.paytype = customEventData;
    }
    /**
     * 获取商品列表
     */
    private getGoodList() {
        let _this = this;
        httpApi.getGoodList((result)=>{
            _this.result_data = result.data;
            uiManager.showWaiting();
            _this.initUI();
        })
    }
}

